package pCloud.acesscontrol;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

import pCloud.PCloudAttributeAndType;

import com.sun.xacml.Target;
import com.sun.xacml.TargetMatch;
import com.sun.xacml.attr.AttributeDesignator;
import com.sun.xacml.attr.IntegerAttribute;
import com.sun.xacml.attr.StringAttribute;

/**
 * @author ttadinh
 * Matching resource, which is the stream ID
 */
public class ResourceMatchInteger extends Match{
	int streamId;
	public ResourceMatchInteger(int si){
		this.streamId = si;
	}
	
	@Override
	public List getMatchTarget() throws Exception {
		List resources = new ArrayList();
		List resource = new ArrayList();

		URI resourceDesignatorType = new URI(PCloudAttributeAndType.TYPE_INTEGER);
		URI resourceDesignatorId = new URI(PCloudAttributeAndType.RESOURCE_STREAM_ID);
		
		AttributeDesignator resourceDesignator = new AttributeDesignator(
				AttributeDesignator.RESOURCE_TARGET, resourceDesignatorType,
				resourceDesignatorId, false);
		
		IntegerAttribute resourceValue = new IntegerAttribute(this.streamId);
		
		resource.add(createTargetMatch(TargetMatch.RESOURCE, PCloudAttributeAndType.MATCH_INTEGER_EQUAL,
				resourceDesignator, resourceValue));		
		resources.add(resource);
		return resources;
	}	
	
}
